import request from '@/utils/request'

/**
 *  1.表名成路由
 *  2.清空表
 *  3.删除表
 *  4.分页查询
 *  5.条件联合查询
 *  6.删除单条记录
 *  7.编辑单条记录(input <=> textarea)
 */

export function showTables() {
  return request({
    url: '/showTables',
    method: 'POST'
  })
}

export function showColumns(tableName) {
  return request({
    url: '/showColumns',
    method: 'POST',
    data: {
      tableName,
      includePrimarykey: false
    }
  })
}

export function pageHandler(tableName, pager) {
  return request({
    url: '/pageHandler',
    method: 'POST',
    data: {
      tableName,
      pager
    }
  })
}

export function truncateTable(tableName) {
  return request({
    url: '/truncateTable',
    method: 'POST',
    data: {
      tableName
    }
  })
}

export function dropTable(tableName) {
  return request({
    url: '/dropTable',
    method: 'POST',
    data: {
      tableName
    }
  })
}

export function deleteHandler(tableName, where) {
  return request({
    url: '/deleteHandler',
    method: 'POST',
    data: {
      tableName,
      where
    }
  })
}

export function updateHandler(tableName, where, data) {
  return request({
    url: '/updateHandler',
    method: 'POST',
    data: {
      tableName,
      data,
      where
    }
  })
}

export function showPrimaryKey() {
  return request({
    url: '/showPrimaryKey',
    method: 'POST'
  })
}
